package org.example.demo2;

import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author Gong.Yang
 */
@Slf4j
public class Demo {
    interface Foo {
        void foo();
    }

    static class Target implements Foo {

        @Override
        public void foo() {
            log.info("Im Target foo method");
        }
    }

    public static void main(String[] args) {
        Target target = new Target();

        Foo proxy = (Foo) Proxy.newProxyInstance(Target.class.getClassLoader(),
                new Class[]{Foo.class},
                (p, method, args1) -> {
                    log.info("proxy before");
                    Object result = method.invoke(target, args1);
                    log.info("proxy after");
                    return result;
                });

        proxy.foo();

    }
}
